function FacebookComment(name,image,comment,type,time){
	var _name = name;
	var _path = "img";
	var _image = image;
	var _comment = comment;
	var _time = time;
	var _type = type;

	this.getType = function(){return _type;}
	this.getName = function(){return _name;}

	this.render = function(container){

		var content = document.createElement("div");
		content.setAttribute("class","fb-comment-content");

		var img = document.createElement("img");
		img.setAttribute("src",_image);

		var info = document.createElement("div");
		info.setAttribute("class","fb-comment-info");

		var span = document.createElement("span");
		span.appendChild(document.createTextNode(_name));

		var p = document.createElement("p");
		p.appendChild(document.createTextNode(_time));

		content.appendChild(img);
		info.appendChild(span);
		info.appendChild(document.createTextNode(_comment));
		info.appendChild(p);
		content.appendChild(info)

		container.appendChild(content);
	}
}

function MovieWeek(){
	var _movies = [];
	var _container;
	var _selectedMovie;

	var _info;
	var that = this;

	this.getContainer = function(){return _container;};
	this.getSelectedMovie = function(){return _selectedMovie;};

	this.addMovie = function(movie,id){
		movie.setId(id);
		movie.addClickListener(this.movieClicked);
		_movies.push(movie);
	}

	this.render = function(container){
		_container = container;
		for(i=0;i<_movies.length;i++){
			_container.appendChild(_movies[i].render());
		}
	}

	this.movieClicked = function(movie){
		var counter = 0;
		var expand = function(){
			if(counter==2){
				movie.expand();
				_selectedMovie = movie;
				that.createInfo(movie);
				$(".btn.week.mostrar").fadeIn();
				$(".btn.week.next").fadeIn();
			}
		};

		for(i=0;i<_movies.length;i++){
			if(movie.getId()!=_movies[i].getId()){
				_movies[i].fadeOut(function(){
					counter++;
					expand();
				});
			}
		}
	}

	this.createInfo = function(movie){
		_info = document.createElement("div");
		_info.setAttribute("class","poster-collection-big-info");

		var title = document.createElement("p");
		title.appendChild(document.createTextNode(movie.getName()));

		var actors = document.createElement("span");
		actors.appendChild(document.createTextNode("Atores: " + movie.getActors()[0].name + " e " + movie.getActors()[1].name));

		var gender = document.createElement("span");
		gender.appendChild(document.createTextNode(movie.getGender()));

		var fbContainer = document.createElement("div");
		fbContainer.setAttribute("class","fb-comment-container");

		_info.appendChild(title);
		_info.appendChild(actors);
		_info.appendChild(document.createElement("br"));
		_info.appendChild(gender);


		var comments = movie.getComments();
		for(i=0;i<comments.length;i++){
			comments[i].render(fbContainer);
		}

		_info.appendChild(fbContainer);
		_container.appendChild(_info);
	}

	this.allMovies = function(){
		$(_info).fadeOut();
		_container.removeChild(_info);
		_selectedMovie.deselect();


		_selectedMovie.shrink(function(){
			for(i=0;i<_movies.length;i++){
				_movies[i].fadeIn();
				_movies[i].shrink();
			}			


		});

		$(".btn.week.mostrar").fadeOut();
		$(".btn.week.next").fadeOut();
	}

	this.randomize = function(){
		var moviesLen = _movies.length;
		var _randMovies = [];
		for(var i=0;i<moviesLen;i++){
			var randNum = parseInt( (Math.random()*100)%(_movies.length) );
			_randMovies.push(_movies[randNum]);			
			_movies.splice(randNum,1);
		}

		_movies = _randMovies;
	}
}

function Movie(name,image,actors,genero){
	var _name = name;
	var _image = image;
	var _path = "img";
	var _actors = actors;
	var _genero = genero;
	var _comments = [];
	var _blockbuster = false;

	var _container;
	var _content;
	var _info;

	var _id;
	var _fnClickCallback;

	this.getName = function(){return _name;};
	this.getImage = function(){return _path + "/" + _image;};
	this.getActors = function(){return _actors;};
	this.getComments = function(){return _comments;};
	this.addComment = function(c){_comments.push(c);};
	this.setActors = function(actors){_actors = actors;}
	this.getGender = function(){return _genero;};
	this.setId = function(id){_id=id;};
	this.getId = function(){return _id;};
	this.deselect = function(){_selected = false;}
	this.setBlockbuster = function(v){ _blockbuster=v;}

	var that = this;
	var _selected = false;

	this.render = function(){
		
		_container = document.createElement("div");
		_container.setAttribute("class","poster-collection-container");

		_content = document.createElement("div");
		_content.setAttribute("class","poster-collection-content");

		var img = document.createElement("img");
		img.setAttribute("src",that.getImage());

		_info = document.createElement("div");
		_info.setAttribute("class","poster-collection-info");
		var spanName = document.createElement("span");
		spanName.appendChild(document.createTextNode(_name))
		
		_info.appendChild(spanName);
		_info.appendChild(document.createElement("br"));
		_info.appendChild(document.createTextNode(_actors[0].name));
		_info.appendChild(document.createElement("br"));
		_info.appendChild(document.createTextNode(_actors[1].name));
		_info.appendChild(document.createElement("br"));
		_info.appendChild(document.createTextNode(_genero));
		_info.appendChild(document.createElement("br"));		
		//_info.appendChild(document.createTextNode(_id));


		if(_blockbuster){
			var prec = document.createElement("p");
			prec.appendChild(document.createTextNode("Recorde de publico: Mais de 100.000.000 de expectadores!"));
			_info.appendChild(prec);
		}

		_content.appendChild(img);
		_content.appendChild(_info);

		_container.appendChild(_content);

		_container.addEventListener("click", function(){if(!_selected){_selected=true; return _fnClickCallback(that);}} );

		return _container;
	}

	this.addClickListener = function(fn_click_callback){
		_fnClickCallback = fn_click_callback;
	}

	this.expand = function(callback){
		$(_container).animate({width:288,height:360});
		$(_content).animate({width:288,height:360});
		$(_info).fadeOut(callback);
	}

	this.shrink = function(callback){
		$(_container).animate({width:180,height:220});
		$(_content).animate({width:180,height:220});
		$(_info).fadeIn(callback);
	}

	this.fadeIn = function(callback){
		$(_container).fadeIn(callback);
	}

	this.fadeOut = function(callback){
		$(_container).fadeOut(callback);
	}

	this.mouseOver = function(){

	}
}
